home *** CD-ROM | disk | FTP | other *** search
- /*
- File: FragmentTool.c
-
- Contains: Main event loop and basic keyboard/mouse processing
-
- Written by: Chris White, Developer Technical Support
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- 9/28/95 CW First release
-
- */
-
-
-
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __DESK__
- #include <Desk.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
-
- #define __MAIN__
-
-
- #include "FragmentTool.h"
-
- #include "Prototypes.h"
-
- #if defined(powerc) && !defined(__MWERKS__) // MetroWerks declares "qd" in their runtime
- QDGlobals qd;
- #endif
-
-
-
-
- void main ( void );
- static void DoKey ( EventRecord*theEvent );
- static void DoMouseDown ( EventRecord* theEvent );
- static void EventLoop ( void );
-
-
-
-
- void main ( void )
- {
- MaxApplZone ( );
-
- // We don't use too many more handles, so we onyl need to call
- // MoreMasters a couple of times.
- MoreMasters ( );
- MoreMasters ( );
-
-
- InitToolbox ( ); // Init toolbox stuff
- InitApplication ( ); // Init application specific stuff
- EventLoop ( );
-
-
- return;
- }
-
-
-
- static void EventLoop ( void )
- {
- OSErr theErr;
- EventRecord theEvent;
-
-
- while ( !gQuit )
- {
- WaitNextEvent ( everyEvent, &theEvent, gSleepTime, nil );
-
- switch ( theEvent.what )
- {
- case nullEvent:
- {
- DialogRef theDialog;
-
- theDialog = FrontWindow ( );
- if ( GetWindowType ( theDialog ) == kGetInfoWindowType )
- TEIdle ( ((DialogPeek) theDialog)->textH );
- }
- break;
-
- case mouseDown:
- DoMouseDown ( &theEvent );
- break;
-
- case keyDown:
- case autoKey:
- DoKey ( &theEvent );
- break;
-
- case activateEvt:
- DoActivate ( &theEvent );
- break;
-
- case updateEvt:
- DoUpdate ( &theEvent );
- break;
-
- case osEvt:
- if ( (theEvent.message >> 24) & suspendResumeMessage ) /* suspend or resume */
- {
- /* Modify the event record to look like an activate/deactivate event */
- theEvent.modifiers = theEvent.message; /* Copy suspend/resume flag */
- theEvent.message = (long) FrontWindow ( );
- DoActivate ( &theEvent );
- }
- break;
-
- case kHighLevelEvent:
- theErr = AEProcessAppleEvent ( &theEvent );
- break;
- }
- }
-
- return;
-
- } // EventLoop
-
-
-
- static void DoMouseDown ( EventRecord* theEvent )
- {
- Point globalPt = theEvent->where;
- int16 windowPart;
- WindowRef theWindow;
- long theMenu;
-
-
- windowPart = FindWindow ( globalPt, &theWindow );
- switch ( windowPart )
- {
- case inMenuBar:
- theMenu = MenuSelect ( globalPt );
- MenuDispatch ( theMenu );
- break;
-
- case inSysWindow:
- // The SystemClick toolbox routine handles system events
- SystemClick ( theEvent, theWindow );
- break;
-
- case inGoAway:
- if ( TrackGoAway ( theWindow, theEvent->where ) )
- {
- // Very easy to implement, and very useful on occasion
- if ( theEvent->modifiers & optionKey )
- DoCloseAllDocuments ( );
- else
- DoCloseDocument ( theWindow );
- }
- break;
-
- case inDrag:
- DoDragWindow ( theWindow, theEvent );
- break;
-
- case inGrow:
- DoGrowWindow ( theWindow, theEvent );
- break;
-
- case inContent:
- DoContentClick ( theWindow, theEvent );
- break;
-
- case inZoomIn:
- case inZoomOut:
- DoZoomWindow ( theWindow, theEvent, windowPart );
- break;
- }
-
- return;
-
- } // DoMouseDown
-
-
-
- static void DoKey ( EventRecord* theEvent )
- {
- char keyPressed = (theEvent->message & charCodeMask);
-
-
- if ( theEvent->modifiers & cmdKey )
- {
- // Command keys get handled by the menu handling routines
- AdjustMenus ( );
- MenuDispatch ( MenuKey ( keyPressed ) );
- }
- else
- {
- // Pass other key strokes to the dialog handling routines
- int16 itemHit;
- WindowRef theWindow = FrontWindow ( );
-
- if ( IsMovableModal ( theWindow ) )
- {
- if ( DialogSelect ( theEvent, &theWindow, &itemHit ) )
- DoDialogItemHit ( theWindow, itemHit );
- }
- }
-
- return;
-
- } // DoKey
-
-
-
-
-